<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="PID" prop="pid">
        <el-input
          v-model="queryParams.pid"
          placeholder="请输入PID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="location" prop="location">
        <el-input
          v-model="queryParams.location"
          placeholder="请输入工位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="result" prop="result">
        <el-select
          v-model="queryParams.result"
          placeholder="请选择"
          clearable
          @keyup.enter.native="handleQuery"
          @change="handleSelectChange"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.l"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
    <el-col :span="1.5">
      <el-button
        type="danger"
        plain
        icon="el-icon-delete"
        size="mini"
        :disabled="multiple"
        @click="handleDelete"
        v-hasPermi="['software:software:remove']"
      >删除</el-button>
    </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="tableList"
      @selection-change="handleSelectionChange"
      border
      style="width: 100%;"
      :show-overflow-tooltip="true"
      empty-text="暂无数据"
    >
      <el-table-column type="selection" align="center" width="55"></el-table-column>
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="PID" align="center" prop="pid"/>
      <el-table-column label="车系" align="center" prop="carName"/>
      <el-table-column label="工位" align="center" prop="location"/>
      <el-table-column label="result" align="center" prop="result"/>
      <el-table-column label="测试时间" align="center" prop="testTime"/>
      <el-table-column label="统计号" align="center" prop="statId"/>
      <el-table-column label="设备" align="center" prop="device"/>
      <el-table-column label="电子控制单元" align="center" prop="ecu"/>
      <el-table-column label="协议文本" align="center" prop="text"/>
      <el-table-column label="统计块文本" align="center" prop="statText"/>
      <el-table-column label="结果" align="center" prop="outcome"/>
      <el-table-column label="DTC" align="center" prop="dtc"/>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" />
    <import-table ref="import" @ok="handleQuery" />
    <create-table ref="create" @ok="handleQuery" />
  </div>
</template>

<script>
import {listSwCar,deletesoftware} from "@/api/software/software";

export default {
  name: "Software",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 唯一标识符
      uniqueId: "",
      // 选中数组
      ids: [],
      // 选中表数组
      tableNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 表数据
      tableList: [],
      // 日期范围
      dateRange: "",
      // 查询参数
      queryParams: {
        ipaddr: undefined,
        tableName: undefined,
        tableComment: '' // 假设这是下拉列表绑定的模型
      },
      options: [
        // 下拉列表的选项数组
        { value: 'OK', label: '选项1' },
        { value: 'NOOK', label: '选项2' },
        // 可以继续添加更多选项
      ],
    };
  },
  created() {
    this.getList();
  },
  activated() {
    const time = this.$route.query.t;
    if (time != null && time != this.uniqueId) {
      this.uniqueId = time;
      this.queryParams.pageNum = Number(this.$route.query.pageNum);
      this.getList();
    }
  },
  methods: {
    getList() {
      this.loading = true;
      listSwCar(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.multipleSelection =selection;
    },
    handleSelectChange(newValue) {
      // 当选择的值变化时，这里将接收新的值作为参数
      console.log('选中的值变化为:', newValue);
      // 在这里可以执行进一步的逻辑处理
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    handleDelete(row) {
     const ids=row.id || this.ids;
     this.$modal.confirm("是否确认要删除ID为"+ids+"的数据项").then(function(){
       return deletesoftware(ids);
     }).then(()=>{
       this.getList();
       this.$modal.confirm("删除成功")
     }).catch(()=>{});
    }
  }
};


</script>
